package com.jht.engine.platsign;

import android.os.SystemClock;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
import java.util.SortedMap;

/* loaded from: classes.dex */
public class SignUtil {
    public static boolean validSign(String str, String str2, String str3, String str4) {
        String str5;
        String[] strArr = {str2, str3, str4};
        Arrays.sort(strArr);
        try {
            str5 = byteToStr(MessageDigest.getInstance("SHA-1").digest((strArr[0] + strArr[1] + strArr[2]).getBytes()));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            str5 = null;
        }
        if (str5 != null) {
            return str5.equals(str.toUpperCase());
        }
        return false;
    }

    private static String byteToStr(byte[] bArr) {
        String str = "";
        for (int i = 0; i < bArr.length; i++) {
            str = str + byteToHex(bArr[i]);
        }
        return str;
    }

    private static String byteToHex(byte b) {
        char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        return new String(new char[]{cArr[(b >>> 4) & 15], cArr[b & 15]});
    }

    public static String genrateKey() {
        Random random = new Random(SystemClock.elapsedRealtime());
        String str = "";
        for (int i = 0; i < 16; i++) {
            str = str + random.nextInt(10);
        }
        return str;
    }

    public static String signature(SortedMap<String, String> sortedMap) {
        StringBuilder sb = new StringBuilder();
        for (String str : sortedMap.keySet()) {
            sb.append(str);
            sb.append("=");
            sb.append(sortedMap.get(str));
            sb.append("&");
        }
        sb.setLength(sb.length() - 1);
        return encryptSHA1(sb.toString());
    }

    public static String encryptSHA1(String str) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
            messageDigest.update(str.getBytes());
            byte[] digest = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b & 255);
                if (hexString.length() < 2) {
                    stringBuffer.append(0);
                }
                stringBuffer.append(hexString);
            }
            return stringBuffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
}
